<?php

use yii\helpers\Html;
use kartik\grid\GridView;

//\backend\assets\CheckBoxAsset::register($this);
/* @var $this yii\web\View */
/* @var $searchModel app\modules\lenders\models\search\LendinvestmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '月月金返息';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="lendinvestment-index">

    <?php echo $this->render('_searchInterest', ['model' => $searchModel,'dataProvider'=>$dataProvider]); ?>

    <p>
        <?php // Html::a('Create Lendinvestment', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'responsive' => true,
        'hover' => true,
        'pjax' => true,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
//            'lendInvestID',
//            'lenderID',
            ['label' => '理财客户', 'value' => 'lenders.userName'],
            ['label' => '省份', 'value' => 'banks.province'],
            ['label' => '城市', 'value' => 'banks.city'],
            ['label' => '银行名称', 'value' => 'banks.bankName'],
            ['label' => '开户行名称', 'value' => 'banks.branchBankName'],
            ['label' => '收款方名称', 'value' => 'banks.bankUserName'],
            ['label' => '收款方银行账号', 'value' => 'banks.cardID'],
            [
                'label' => '金额(元)',
                'value' => function($data) {
            return getIncomes($data);
        }
            ],
            ['label' => '合同编号', 'value' => 'contractNo'],
            ['label' => '备注（50字以内）', 'value' => function() {
            return "北京通金所资产管理有限公司月月金回息款，请查收.";
        }],
            ['label' => '理财产品利率', 'value' => function($data){
            return $data->investRate.'%';
            }],
            ['label' => '到期日期', 'value' => 'expireDate'],
            ['label' => '投资金额（万元）', 'value' => 'investAmt'],
//            'paymentType',
//            [
//                'label' => '天数',
//                'value' => function($data) {
//            return getInvestDay($data);
//        }
//            ],
            ['label' => '起息日期', 'value' => 'qixiDate'],
//            'qixiDate',
            ['label' => '进账日期', 'value' => 'querenshuTime'],
            ['label' => '公司名称', 'value' => 'companyName'],
//             'submitDate',
//             'toWithholdDate',
//             'isDeleted',
//             'createTime',
//             'createUser',
//             'updateTime',
//             'updateUser',
//             'RepaymentDay',
//             'curIncomes',
//             'curIncomesRate',
//             'discountRate',
//             'comments',
//             'payBankID',
//             'receiveBankID',
//             'contractNo',
//             'lenderNo',
//             'seqNo',
//             'customerManagerName',
//             'customerManagerID',
//             'teamManagerName',
//             'teamManagerID',
//             'operateManagerName',
//             'operateManagerID',
//             'yunYingManagerName',
//             'yunYingManagerID',
//             'yunYingManagerTeamBuildName',
//             'yunYingManagerTeamBuildNameID',
//             'subCompanyManagerName',
//             'subCompanyManagerID',
//             'VPName',
//             'VPID',
//             'qixiDate',
//             'innerComments',
//             'companyID',
//             'deptID',
//             'companyName',
//             'deptName',
//             'addressID',
//             'phoneID',
//             'renewDate',
//             'jixiaoDate',
//             'postType',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]);
    ?>

</div>
<?php

function getInvestDay($data) {
//    $_thisMonth  = $_GET['Lendinvestment']['querenshuTime'];

    $_days = abs(((strtotime(date('Y-m', time()) . '-30')) - strtotime($data->qixiDate)) / 86400);

    if ($_days >= 30) {
        return 30;
    } else
        return $_days + 1;
}

function getIncomes($data) {
    $_day = getInvestDay($data);
    $_income = 10000 * $data->investAmt * $data->investRate / 100 / 12 * $_day / 30;
    return sprintf("%.2f", $_income);
}
?>